﻿using AutoMapper.Internal.Mappers;
using EMS.system.IEntityAppService.BaseData.IRoleService;
using EMS.system.IEntityAppService.BaseData.IRoleService.RoleDto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using System;

namespace EMS.system.Web.Controllers.BaseData
{
    public class RoleController : Controller
    {
        private readonly IRoleAppService _roleService;

        public RoleController(IRoleAppService roleService)
        {
            _roleService = roleService;
        }

        public IActionResult RoleIndex()
        {
            return View();
        }

        public IActionResult Add(int id)
        {
            ViewBag.id = id;
            return View();
        }

        public IActionResult AccountRole()
        {
            return View();
        }

        /// <summary>
        /// 角色新增
        /// </summary>
        /// <param name="addDto"></param>
        /// <returns></returns>
        public async Task<int> RoleAdd(RoleAddDto addDto)
        {
            int result = await _roleService.RoleAdd(addDto);
            return result;
        }

        /// <summary>
        /// 显示角色
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public async Task<JsonResult> RoleList(string? name, int page, int limit)
        {
            var result = await _roleService.RoleList(name, page, limit);
            return Json(new {data = result.Queryable,count = result.RowCount,code = 0,msg = ""});
        }

        /// <summary>
        /// 删除角色
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> RoleDel(string ids)
        {
            var result = await _roleService.RoleDel(ids);
            return result;
        }

        /// <summary>
        /// 获取单个角色信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<RoleUpdDto> GetSingRole(int id)
        {
            var result = await _roleService.GetSingRole(id);
            return result;
        }

        /// <summary>
        /// 编辑角色信息
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<int> RoleUpd(RoleUpdDto dto)
        {
            var result = await _roleService.RoleUpd(dto);
            return result;
        }
    }
}
